package cn.gs.util.set;

// @author gs
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class TypeManager {

    public static List<Double> castDouble(Iterable<String> vals) {
        List<Double> r = new LinkedList<Double>();
        for (String s : vals) {
            r.add(Double.valueOf(s));
        }
        return r;
    }

    public static String[] object2str(Object[] obj) {
        String[] r = new String[obj.length];
        for (int i = 0; i < obj.length; ++i) {
            r[i] = obj[i] == null ? null : obj[i].toString();
        }
        return r;
    }

    public static <T> List<T> array2list(T... ls) {
        return Arrays.asList(ls);
    }

    public static String list2str(List<String> ls) {
        return list2str(ls, " ");
    }

    public static String list2str(List<String> ls, String split) {
        if (ls == null) {
            return "";
        }
        boolean flag = false;
        StringBuilder sb = new StringBuilder();
        for (String s : ls) {
            if (s != null) {
                if (flag) {
                    sb.append(split);
                } else {
                    flag = true;
                }
                sb.append(s);
            }
        }
        return sb.toString();
    }
}
